package main

/**
go的多态学习


*/

import "fmt"

// 本质是一个指针
type AnimalIF interface {
	Sleep()
	GetColor() string
	GetType() string
}

type Cat struct {
	color string //猫的颜色

}

func (this *Cat) Sleep() {
	fmt.Println("Cat is Sleep")
}

func (this *Cat) GetColor() string {
	return this.color
}

func (this *Cat) GetType() string {
	return "Cat"
}

type Dog struct {
	color string //狗的颜色

}

func (this *Dog) Sleep() {
	fmt.Println("Dog is Sleep")
}

func (this *Dog) GetColor() string {
	return this.color
}

func (this *Dog) GetType() string {
	return "Cat"
}

func showAnimal(animalIF AnimalIF) {
	animalIF.Sleep()
}

func main() {
	//父类指针
	var animal AnimalIF

	animal = &Cat{"Green"}
	showAnimal(animal)
	animal = &Dog{"dark"}
	showAnimal(animal)
}
